import {takeEvery } from 'redux-saga/effects';
import { CRUD_UPDATE_SUCCESS,  CRUD_CREATE_SUCCESS, CRUD_UPDATE_FAILURE, CRUD_CREATE_FAILURE, CRUD_DELETE_FAILURE, CRUD_DELETE_SUCCESS, CRUD_DELETE_MANY_SUCCESS, CRUD_DELETE_MANY_FAILURE } from 'ra-core';
import { socket } from './realtime';


export default function* onDataChangeSaga() {
    yield takeEvery(CRUD_UPDATE_SUCCESS, function* () {
        yield socket.emit('onDataChange',1);
    });
    yield takeEvery(CRUD_CREATE_SUCCESS, function* () {
        yield socket.emit('onDataChange', 1);
       
    });
    yield takeEvery(CRUD_UPDATE_FAILURE, function* () {
        yield socket.emit('onDataChange', 0);
       
    });
    yield takeEvery(CRUD_CREATE_FAILURE, function* () {
        yield socket.emit('onDataChange', 0);
       
    });
    yield takeEvery(CRUD_DELETE_FAILURE, function* () {
        yield socket.emit('onDataChange', 0);
       
    });
    yield takeEvery(CRUD_DELETE_SUCCESS, function* () {
        yield socket.emit('onDataChange', 1);
       
    });
    yield takeEvery(CRUD_DELETE_MANY_SUCCESS, function* () {
        yield socket.emit('onDataChange', 1);
       
    });
    yield takeEvery(CRUD_DELETE_MANY_FAILURE, function* () {
        yield socket.emit('onDataChange', 0);
       
    });
}


